﻿using Microsoft.AspNetCore.Builder;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace coreEntityFramework.Extend
{
    public static class ExceptionExpression
    {

        public static void UseExcetionOption(this IApplicationBuilder builder)
        {
            ExceptionHandlerOptions exceptionHandlerOptions = new ExceptionHandlerOptions();

            //添加全局异常处理的方法
            var exceptionHandler = new ExceptionHandlerOptions();
            exceptionHandler.ExceptionHandler = async (context) =>
            {
                if (context.Response.StatusCode == 500)
                {
                    await Task.Run(() =>
                    {
                        context.Response.StatusCode = 200;
                        //context.Response.Body.WriteAsync(null,0,0);
                        //context.Response.Headers.Add("test", "kkkkk");
                    });
                }
            };

            //全局异常处理
            builder.UseExceptionHandler(exceptionHandler);
           
        }




    }
}
